﻿// ———————————————————————–
// <copyright file="HealchCareProviderType.cs" company="The MITRE Corporation">
//    Copyright (c) 2012 The MITRE Corporation. All rights reserved.
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//    http://www.apache.org/licenses/LICENSE-2.0
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.
// </copyright>
// ———————————————————————–
/////////////////////////////////////////////////////////////////////////////////////////////////
// HealchCareProviderType.cs - Library Class for the TEP Message
// Project: IC.NET - TEP Library
//
// Language:    C#, .NET 4.0
// Platform:    Windows 7, VS 2010 Beta 2
// Author:      Lizzie DeYoung MITRE
//              Brian Wilkins  MITRE

/////////////////////////////////////////////////////////////////////////////////////////////////

// Copyright (c) 2012 The MITRE Corporation. All rights reserved.
//
// NOTICE
// This software was produced for the U. S. Government
// under Contract No. FA8721-12-C-0001, and is
// subject to the Rights in Noncommercial Computer Software
// and Noncommercial Computer Software Documentation Clause
// (DFARS) 252.227-7014 (JUN 1995)using System;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using EDXLSharp.EDXLCTLib;
using EDXLSharp.CIQLib;

namespace EDXLSharp.EDXLTEPLib
{
  public class HealthCareProviderType : IComposable
  {

    #region Private Member Variables

    private ValueKeyType providerNumber;
    private EDXLStringTypeWrapper providerName;
    private AddressType providerJurisdiction; // TODO: HealthCareProviderType.providerJurisdiction - is this the right address type? should be xal:AddressType
    private ValueKeyType providerCountry;
    private ValueListType providerType;
    private EDXLStringTypeWrapper providerDomainName;
    private EDXLStringTypeWrapper personnelIDNumber;
    private AddressType personnelJurisdiction;
    private ValueListType personnelCertificationLevel;
    private TransportType transport;

    private string DefaultElementName = "HealthCareProvider";

    #endregion //Private Member Variables

    #region Constructors

    public HealthCareProviderType()
    {
    }

    #endregion // Constructors

    #region Public Accessors

    public ValueKeyType ProviderNumber
    {
      get { return this.providerNumber; }
      set { this.providerNumber = value; }
    }

    public EDXLStringTypeWrapper ProviderName
    {
      get { return this.providerName; }
      set { this.providerName = value; }
    }

    public AddressType ProviderJurisdiction
    {
      get { return this.providerJurisdiction; }
      set { this.providerJurisdiction = value; }
    }

    public ValueKeyType ProviderCountry
    {
      get { return this.providerCountry; }
      set { this.providerCountry = value; }
    }

    public ValueListType ProviderType
    {
      get { return this.providerType; }
      set { this.providerType = value; }
    }

    public EDXLStringTypeWrapper ProviderDomainName
    {
      get { return this.providerDomainName; }
      set { this.providerDomainName = value; }
    }

    public EDXLStringTypeWrapper PersonnelIDNumber
    {
      get { return this.personnelIDNumber; }
      set { this.personnelIDNumber = value; }
    }

    public AddressType PersonnelJurisdiction
    {
      get { return this.personnelJurisdiction; }
      set { this.personnelJurisdiction = value; }
    }

    public ValueListType PersonnelCertificationLevel
    {
      get { return this.personnelCertificationLevel; }
      set { this.personnelCertificationLevel = value; }
    }

    public TransportType Transport
    {
      get { return this.transport; }
      set { this.transport = value; }
    }

    #endregion // Public Accessors

    #region Public Member Functions

    public void WriteXML(XmlWriter xwriter)
    {
      this.WriteXML(xwriter, this.DefaultElementName);
    }

    public void WriteXML(XmlWriter xwriter, string name)
    {
      this.Validate();

      xwriter.WriteStartDocument(false);
      xwriter.WriteStartElement(name);

      if (this.providerNumber != null)
      {
        this.providerNumber.WriteXML(xwriter, "providerNumber");
      }

      if (this.providerName != null)
      {
        this.providerName.WriteXML(xwriter, "providerName");
      }

      if (this.providerJurisdiction != null)
      {
        xwriter.WriteStartElement("providerCountry");
        this.providerJurisdiction.WriteXML(xwriter);
        xwriter.WriteEndElement();
      }

      if (this.providerCountry != null)
      {
        this.providerCountry.WriteXML(xwriter, "providerCountry");
      }

      if (this.providerType != null)
      {
        this.providerType.WriteXML(xwriter, "providerType");
      }

      if (this.providerDomainName != null)
      {
        this.providerDomainName.WriteXML(xwriter, "providerDomainName");
      }

      if (this.personnelIDNumber != null)
      {
        this.personnelIDNumber.WriteXML(xwriter, "personnelIDNumber");
      }

      if (this.personnelJurisdiction != null)
      {
        xwriter.WriteStartElement("personnelCertificationLevel");
        this.personnelJurisdiction.WriteXML(xwriter);
        xwriter.WriteEndElement();
      }

      if (this.personnelCertificationLevel != null)
      {
        this.personnelCertificationLevel.WriteXML(xwriter, "personnelCertificationLevel");
      }

      if (this.transport != null)
      {
        this.transport.WriteXML(xwriter, "transport");
      }

      xwriter.WriteEndElement();
    }

    public void ReadXML(XmlNode rootnode)
    {
      foreach (XmlNode node in rootnode)
      {
        if (String.IsNullOrEmpty(node.InnerText))
        {
          continue;
        }

        switch (node.LocalName)
        {
          case "providerNumber":
            if (this.providerNumber == null)
            {
              this.providerNumber = new ValueKeyType();
            }
            this.providerNumber.ReadXML(node);
            break;

          case "providerName":
            if (this.providerName == null)
            {
              this.providerName = new EDXLStringTypeWrapper();
            }
            this.providerName.ReadXML(node);
            break;

          case "providerJurisdiction":
            if (this.providerJurisdiction == null)
            {
              this.providerJurisdiction = new AddressType();
            }
            this.providerJurisdiction.ReadXML(node);
            break;

          case "providerCountry":
            if (this.providerCountry == null)
            {
              this.providerCountry = new ValueKeyType();
            }
            this.providerCountry.ReadXML(node);
            break;

          case "providerType":
            if (this.providerType == null)
            {
              this.providerType = new ValueListType();
            }
            this.providerType.ReadXML(node);
            break;

          case "providerDomainName":
            if (this.providerDomainName == null)
            {
              this.providerDomainName = new EDXLStringTypeWrapper();
            }
            this.providerDomainName.ReadXML(node);
            break;

          case "personnelIDNumber":
            if (this.personnelIDNumber == null)
            {
              this.personnelIDNumber = new EDXLStringTypeWrapper();
            }
            this.personnelIDNumber.ReadXML(node);
            break;

          case "personnelJurisdiction":
            if (this.personnelJurisdiction == null)
            {
              this.personnelJurisdiction = new AddressType();
            }
            this.personnelJurisdiction.ReadXML(node);
            break;

          case "personnelCertificationLevel":
            if (this.personnelCertificationLevel == null)
            {
              this.personnelCertificationLevel = new ValueListType();
            }
            this.personnelCertificationLevel.ReadXML(node);
            break;

          case "transport":
            if (this.transport == null)
            {
              this.transport = new TransportType();
            }
            this.transport.ReadXML(node);
            break;
        }
      }

      this.Validate();
    }

    public void Validate()
    {
      if (this.providerNumber == null)
      {
        throw new ArgumentNullException("A providerNumber element is required. No null values.");
      }

      if (this.providerName == null)
      {
        throw new ArgumentNullException("A providerName element is required. No null values.");
      }

      if (this.providerJurisdiction == null)
      {
        throw new ArgumentNullException("A providerJurisdiction element is required. No null values.");
      }

      if (this.providerCountry == null)
      {
        throw new ArgumentNullException("A providerCountry element is required. No null values.");
      }

      if (this.providerType == null)
      {
        throw new ArgumentNullException("A providerType element is required. No null values.");
      }
    }

    #endregion // Public Member Functions
  }
}
